﻿package kr.efusioni.debuger.core
{
	import flash.events.AsyncErrorEvent;
	import flash.events.EventDispatcher;
	import flash.events.SecurityErrorEvent;
	import flash.events.StatusEvent;
	import flash.net.LocalConnection;
	
	import kr.efusioni.debuger.event.DebugerEvent;
	
	public class DebugerCoreReceive extends EventDispatcher
	{
		private var NAME: String = "_efustioni_debuger"; 
		
		private var lc: LocalConnection;
		public function DebugerCoreReceive()
		{
			lc = new LocalConnection();
			lc.addEventListener( AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler );
			lc.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler );
			lc.addEventListener( StatusEvent.STATUS, statusHandler );
			lc.allowDomain( "*" );
			lc.client = this;
			try
			{				
				lc.connect( NAME );				
				
			}catch ( error: ArgumentError )
			{
				
			}		
		}
		
		public function message ( $msg: Object, $type: String, $color: Number = 0 ) : void
		{
			var data: Object = new Object();
			data.msg = $msg;
			data.type = $type;
			data.color = $color;
			
			this.dispatchEvent( new DebugerEvent ( DebugerEvent.DATA_RECEIVED, data ) );
		}
		
		
		private function asyncErrorHandler ( e: AsyncErrorEvent ): void
		{
			trace ( " [ AsyncErrorEvent ] " );
		}
		
		private function securityErrorHandler ( e: SecurityError ): void
		{
			trace ( " [ SecurityError  ] " );
		}
		
		private function statusHandler ( e: StatusEvent ): void
		{
			trace ( " [ StatusEvent ] " ) ;
		}
	}
}